# ./app/__init__.py
from flask import Flask
from app import config
from app.config import create_db_connection
from app.config import generate_random_string

def create_app():

    app = Flask(__name__)
    app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'

    create_db_table()

    from .main.views import main_bp
    app.register_blueprint(main_bp)

    return app


def create_db_table():
    conn, cursor = create_db_connection()

    # 临时文件表
    cursor.execute('''
              CREATE TABLE IF NOT EXISTS tmp_files (
              id INT AUTO_INCREMENT PRIMARY KEY,
              file_url VARCHAR(100),
              file_name VARCHAR(100),
              storage_name VARCHAR(100),
              file_size INT,
              expiration_time TIMESTAMP,
              upload_time TIMESTAMP
          )''')


    conn.commit()
    cursor.close()
    conn.close()